package jfxtras.scene.control;

/**
 * Data provider for the an integer range, also uses an Integer as the index.
 * Basically here goes: index = value 
 */
public class SpinnerXDataProviderInteger
implements SpinnerXDataProvider<Integer, Integer>
{
	public SpinnerXDataProviderInteger()
	{
		this(Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
	}
	
	public SpinnerXDataProviderInteger(int min, int max)
	{
		this(min, max, 1);
	}
	
	public SpinnerXDataProviderInteger(int min, int max, int step)
	{
		this.min = min;
		this.max = max;
		this.step = step;
	}
	private int min;
	private int max;
	private int step;
	
	/**
	 * 
	 * @param idx
	 * @return
	 */
	public Integer getPreviousIndex(Integer idx)
	{
		// null returns first index
		if (idx == null) return Integer.valueOf(min);
		
		// decrement				
		if (idx == min) return null; // no previous index
		Integer lIndex = idx - 1;
		return lIndex;
	}

	/**
	 * 
	 * @param idx
	 * @return
	 */
	public Integer getNextIndex(Integer idx)
	{
		// null returns last index
		if (idx == null) return Integer.valueOf(max);
		
		// increment
		if (idx == max) return null; // no next index
		Integer lIndex = idx + 1;
		return lIndex;
	}
	
	@Override
	public Integer getValue(Integer idx)
	{
		return idx * step;
	}
	
	@Override
	public Integer getIndex(Integer idx)
	{
		return idx / step;
	}

	@Override
	public Integer addValue(Integer value)
	{
		return null; // adding not allowed
	}
}